package yja.gzw.app.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RatingBar
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import yja.gzw.app.R
import yja.gzw.app.model.bean.Itempingjia

class PingjiaAdapter (private val context: Context, private val list: List<Itempingjia>): RecyclerView.Adapter<RecyclerView.ViewHolder>(){
    private var view: View?=null
    private lateinit var neituada: NeituAdapter
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        view= LayoutInflater.from(parent.context).inflate(R.layout.item_view_pingjia,parent,false)

        return ViewHodeView(view!!)
    }

    override fun getItemCount(): Int {
       return list.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if(holder is ViewHodeView){


           val listss = list[position].images.split(",")
            val lisetet= mutableListOf<String>()
            for (listss1 in listss) {

                lisetet.add("http://117ai.32.hzgqapp.com/"+listss1)

            }


            holder.reveiw.layoutManager = GridLayoutManager(context, 3) // 2 列
            neituada = NeituAdapter(context,lisetet)
            holder.reveiw.adapter = neituada


            val requestOptions = RequestOptions.bitmapTransform(CircleCrop())
            Glide.with(context).load("http://117ai.32.hzgqapp.com/"+list[position].user.avatar)
                .apply(requestOptions)
                .into(holder.haoyouname)
                holder.name.text=list[position].user.nickname
                holder.shijian.text=list[position].createtime_text
                holder.neirong.text=list[position].content
            holder.pingfen.rating = list[position].score.toFloat()




        }



    }
    inner class ViewHodeView(itemView: View):RecyclerView.ViewHolder(itemView){
        val haoyouname: ImageView =itemView.findViewById(R.id.touxiang)
        val name: TextView =itemView.findViewById(R.id.name)
        val shijian:TextView=itemView.findViewById(R.id.shijian)
       val neirong:TextView=itemView.findViewById(R.id.neirong)
        var pingfen: RatingBar =itemView.findViewById(R.id.pingfen)
        var reveiw: RecyclerView =itemView.findViewById(R.id.review)




    }
}